package com.hexinfo.dmpro.monitor.util;

import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class ConvertUtil {

    /**
     * list中的map的key转小写
     * @param listMap
     * @return
     */
    public <T> List<Map<String, T>> mapKeytoLower(List<Map<String, T>> listMap){
        if (listMap == null || listMap.size() == 0){
            return listMap;
        }
        List<Map<String, T>> mapList = new ArrayList<>();
        for (Map<String, T> stringStringMap : listMap) {
            Map<String, T> resultMap = new HashMap<>();
            Set<String> sets = stringStringMap.keySet();
            for (String key : sets) {
                resultMap.put(key.toLowerCase(), stringStringMap.get(key));   //key全转小写
            }
            mapList.add(resultMap);
        }
        return mapList;
    }

    /**
     * map的key转小写
     * @param listMap
     * @return
     */
    public <T> Map<String, T> mapKeytoLower(Map<String, T> listMap){
        if (listMap == null){
            return listMap;
        }
        Map<String, T> resultMap = new HashMap<>();
        Set<String> sets = listMap.keySet();
        for (String key : sets) {
            resultMap.put(key.toLowerCase(), listMap.get(key));   //key全转小写
        }
        return resultMap;
    }

//    public List<Map<String, String>> mapKeytoLower(List<Map<String, String>> listMap) {
//        List<Map<String, String>> mapList = new ArrayList<>();
//        for (Map<String, String> stringStringMap : listMap) {
//            Map<String, String> resultMap = new HashMap<>();
//            Set<String> sets = stringStringMap.keySet();
//            for (String key : sets) {
//                resultMap.put(key.toLowerCase(), stringStringMap.get(key));   //key全转小写
//            }
//            mapList.add(resultMap);
//        }
//        return mapList;
//    }
}
